/*
 * @Author: zhengzhuang
 * @since: 2019-12-27 10:17:03
 * @lastTime     : 2020-01-11 10:16:48
 * @LastAuthor   : zhengzhuang
 * @文件相对于项目的路径: /wangyueche_driver/lib/pages/intercity_car/intercity_set_collection_amount.dart
 * @message: 二维码收款设置金额  SetCollectionAmount
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/provider/order_information.dart';
import 'package:provider/provider.dart';

class SetCollectionAmount extends StatefulWidget {
  final String orginPoint;
  final String endPoint;
  final String unitPrice;
  SetCollectionAmount({this.orginPoint, this.endPoint, this.unitPrice});

  @override
  _SetCollectionAmountState createState() => _SetCollectionAmountState();
}

class _SetCollectionAmountState extends State<SetCollectionAmount> {
  String moneyNum;

  @override
  void initState() {
    super.initState();

    moneyNum = '${widget.unitPrice}';
  }

  @override
  Widget build(BuildContext context) {
    OrderInformation providerData = Provider.of<OrderInformation>(context);
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: () {
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
        appBar: AppBar(title: Text('二维码收款')),
        resizeToAvoidBottomPadding: false, //输入框抵住键盘
        body: Center(
          child: Container(
            child: Column(
              children: <Widget>[
                Container(
                    width: double.infinity,
                    height: ScreenUtil().setWidth(150.0),
                    color: Colors.white,
                    alignment: Alignment.center,
                    child: Stack(
                      children: <Widget>[
                        Container(
                          width: ScreenUtil().setWidth(690.0),
                          height: ScreenUtil().setWidth(110.0),
                          decoration: BoxDecoration(
                              color: Color.fromARGB(255, 230, 230, 234),
                              borderRadius: BorderRadius.circular(
                                  ScreenUtil().setSp(15.0))),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceAround,
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  _blueDots(),
                                  SizedBox(width: ScreenUtil().setWidth(10.0)),
                                  Container(
                                    width: ScreenUtil().setWidth(220.0),
                                    child: Text('${widget.endPoint}',
                                        maxLines: 1,
                                        style: TextStyle(
                                            fontSize: ScreenUtil().setSp(34.0),
                                            color: Colors.black87,
                                            fontWeight: FontWeight.w400)),
                                  ),
                                ],
                              ),
                              Icon(Icons.trending_flat,
                                  color: Colors.black,
                                  size: ScreenUtil().setSp(60.0)),
                              Row(
                                children: <Widget>[
                                  _orangeDots(),
                                  SizedBox(width: ScreenUtil().setWidth(10.0)),
                                  Container(
                                      width: ScreenUtil().setWidth(220.0),
                                      child: Text('${widget.orginPoint}',
                                          maxLines: 1,
                                          style: TextStyle(
                                              fontSize:
                                                  ScreenUtil().setSp(34.0),
                                              color: Colors.black87,
                                              fontWeight: FontWeight.w400))),
                                ],
                              ),
                            ],
                          ),
                        ),
                      ],
                    )),
                Container(
                  width: double.infinity,
                  padding: EdgeInsets.only(
                    left: ScreenUtil().setWidth(30.0),
                    right: ScreenUtil().setWidth(30.0),
                  ),
                  height: ScreenUtil().setWidth(300.0),
                  color: Colors.white,
                  child: Column(
                    children: <Widget>[
                      SizedBox(height: ScreenUtil().setHeight(30.0)),
                      Text('扫二维码向我付款',
                          style: TextStyle(
                              fontSize: ScreenUtil().setSp(32.0),
                              color: Colors.black38)),
                      TextField(
                        keyboardType: TextInputType.number,
                        controller: TextEditingController.fromValue(
                            TextEditingValue(
                                // 设置内容
                                text: moneyNum,
                                // 保持光标在最后
                                selection: TextSelection.fromPosition(
                                    TextPosition(
                                        affinity: TextAffinity.downstream,
                                        offset: moneyNum.length)))),
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            fontSize: ScreenUtil().setSp(80.0),
                            color: Colors.black,
                            fontWeight: FontWeight.w400),
                        decoration: InputDecoration(
                          // border: InputBorder.none,
                          // errorText: "errorText",
                          // hintText: "hintText",
                          prefixText: "¥",
                        ),
                        onChanged: (res) {
                          setState(() {
                            moneyNum = res;
                          });
                        },
                      ),
                    ],
                  ),
                ),
                SizedBox(height: ScreenUtil().setHeight(30.0)),
                Text(
                  '司机可通过具体情况修改价格',
                  style: TextStyle(
                      color: Color.fromARGB(255, 255, 153, 0),
                      fontSize: ScreenUtil().setSp(30.0)),
                ),
                SizedBox(height: ScreenUtil().setHeight(150.0)),
                MaterialButton(
                  color: Color.fromARGB(255, 255, 153, 0),
                  minWidth: ScreenUtil().setWidth(690.0),
                  height: ScreenUtil().setHeight(100.0),
                  child: Text(
                    '生成二维码收款',
                    style: TextStyle(
                        fontSize: ScreenUtil().setSp(36.0),
                        color: Colors.white),
                  ),
                  onPressed: () =>
                      providerData.getDriverReceivables(context, moneyNum),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  /// 蓝色圆点
  Widget _blueDots() {
    return Container(
      width: ScreenUtil().setWidth(13.0),
      height: ScreenUtil().setWidth(13.0),
      decoration: BoxDecoration(color: Colors.blue, shape: BoxShape.circle),
    );
  }

  /// 橙色圆点
  Widget _orangeDots() {
    return Container(
      width: ScreenUtil().setWidth(13.0),
      height: ScreenUtil().setWidth(13.0),
      decoration: BoxDecoration(color: Colors.orange, shape: BoxShape.circle),
    );
  }
}
